package com.cdzg.cloud.money.resp;

import com.cdzg.cloud.money.constant.ResultCode;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@NoArgsConstructor
public class PageResp<T> extends BaseResp {

    @ApiModelProperty("当前页")
    private Integer currentPage;

    @ApiModelProperty("单页展示条数")
    private Integer pageSize;

    @ApiModelProperty("总记录条数")
    private Long totalNum;

    @ApiModelProperty("总页数")
    private Integer totalPage;

    @ApiModelProperty("数据列表")
    private List<T> items;

    public PageResp(ResultCode code) {
        super(code);
    }

    public PageResp(Integer currentPage, Integer pageSize, Long totalNum, List<T> items) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalNum = totalNum;
        this.totalPage = (int) ((this.totalNum + (long) this.pageSize - 1L) / (long) this.pageSize);
        this.items = items;
    }

    public void setMessage(ResultCode code) {
        this.setCode(code.getKey());
        this.setMsg(code.getValue());
    }
}
